package com.example.demo.controller;

import com.example.demo.entity.BuildingInfo;
import com.example.demo.service.BuildingInfoService;
import com.example.demo.utils.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author chen huilong
 * @since 2022-10-04
 */
@Api(tags = "宿舍楼信息管理")
@RestController
@RequestMapping("/demo/building-info")
public class BuildingInfoController {

    @Resource
    private BuildingInfoService buildingInfoService;

    @PostMapping("/insertBuildingData")
    @ApiOperation("批量插入宿舍楼数据")
    public Response register() {
        buildingInfoService.insertBuildingData();
        return Response.success();
    }


    @GetMapping("/getBuildingList")
    @ApiOperation("查询宿舍楼列表")
    public Response getBuildingList(HttpServletRequest request) {
        List<String> buildingList = buildingInfoService.getBuildingList(request);
        return Response.success().data("building list", buildingList);
    }

    @GetMapping("/getRemainderBedInfo")
    @ApiOperation("查询每个楼的空余床位总数")
    public Response getRemainderBedInfo(@RequestHeader("access_token") String access_token, HttpServletRequest request) {
        HashMap<String, Integer> buildingInfo = buildingInfoService.getBuildingById(access_token, request);
        return Response.success().data("building info", buildingInfo);
    }

    @PostMapping("/exportStuList")
    @ApiOperation("批量导出学生列表")
    public Response exportStuList() {
        buildingInfoService.exportStuList();
        return Response.success();
    }

}

